package com.czy.fx.day2;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

/********************************************************************
 * @brief
 * @version 0.1
 * @date 2024年12月14日 下午7:53
 * @author czy
 ********************************************************************/
public class Longin extends Application {

    public static void main(String[] args) {
        launch(args);
    }
    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("登录");
        primaryStage.setWidth(500);
        primaryStage.setHeight(300);
        primaryStage.setResizable(false);
        GridPane gridPane = new GridPane();
        gridPane.setStyle("-fx-background-color: #d7ef6d");
        Scene scene = new Scene(gridPane);
        primaryStage.setScene(scene);

        Label name = new Label("账号:");
        Label passworld = new Label("密码:");
        TextField t_name = new TextField();
        PasswordField t_pass = new PasswordField();

        Button login = new Button("登录");
        Button clean = new Button("清除");
        gridPane.add(name, 0, 0);
        gridPane.add(t_name, 1, 0);
        gridPane.add(passworld, 0, 1);
        gridPane.add(t_pass, 1, 1);
        gridPane.add(clean, 0, 2);
        gridPane.add(login, 1, 2);
        gridPane.setAlignment(Pos.CENTER);
        gridPane.setHgap(10);
        gridPane.setVgap(10);
        GridPane.setMargin(login, new Insets(0, 0, 0, 100));

        clean.setOnMouseClicked(event -> {
            t_name.clear();
            t_pass.clear();
        });
        login.setOnMouseClicked(event -> {
            if (t_name.getText().equals("123") && t_pass.getText().equals("123")) {
                System.out.println("登录成功");
            }else{
                System.out.println("账号或密码错误");
            }
        });

        primaryStage.show();
    }




}
